package com.itheima05;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class ClientDemo {
    public static void main(String[] args) throws IOException {
        // 创建客户端 socket
        Socket s = new Socket("127.0.0.1", 10000);

        // 获取输出流，写数据
        OutputStream os = s.getOutputStream();
        os.write("hello.tcp.我来了".getBytes());

        // 接收服务端反馈
        InputStream is = s.getInputStream();
        byte[] bytes = new byte[1024];
        int len = is.read(bytes);
        System.out.println("客户端：" + new String(bytes, 0, len));

        // 释放资源
//        is.close();
//        os.close();
        s.close();
    }
}
